//
//  ClickComentView.m
//  diaoyuren
//
//  Created by 钓鱼人 on 16/3/5.
//  Copyright © 2016年 game. All rights reserved.
//

#import "ClickComentView.h"
#import "TQStarRatingView.h"

@interface ClickComentView ()<StarRatingViewDelegate,UITextViewDelegate>

@property (nonatomic,strong) UILabel *placeHolderLabel;//textView中的水印字体label

@end

@implementation ClickComentView

-(void)awakeFromNib{
    
    self.backgroundColor = RGBA(230, 230, 238, 0.8);
    
    self.textView.delegate = self;
    //水印字体
    [_placeHolderLabel removeFromSuperview];
    _placeHolderLabel = [[UILabel alloc] initWithFrame:CGRectMake(8, 0, CGRectGetWidth(_textView.frame), 30)];
    _placeHolderLabel.textColor = [UIColor lightGrayColor];
    _placeHolderLabel.font = font(SCREEN_WIDTH*0.04);
    _placeHolderLabel.userInteractionEnabled = NO;
    _placeHolderLabel.text = @"请写下对钓场的评价";
    _placeHolderLabel.hidden = ![@"" isEqualToString:self.textView.text];
    [_textView addSubview:_placeHolderLabel];
    
    /**
     *  添加 星星评分
     */
    
    CGFloat hh  = SCREEN_HEIGHT*0.035;
    CGFloat  ww =  (hh*(1.05))*5+(hh/2); //1.05是一个星星的宽高比
    CGFloat yy = 11;
    CGFloat xx = SCREEN_HEIGHT*0.13;
    
    self.starRating = [[TQStarRatingView alloc]initWithFrame:CGRectMake(xx, yy, ww, hh)];
    [self addSubview:self.starRating];
    self.starRating.delegate = self;
    self.starRating.isMove = YES;
    [self.starRating StarForegroundViewWithScore:@"0"];
    
}

-(void)starRatingView:(TQStarRatingView *)view score:(float)score{
    self.sroce.text = [NSString stringWithFormat:@"%.1f分",score*10];
    self.scroceString = [NSString stringWithFormat:@"%.1f",score*10];
}

#pragma mark - text view delegate
-(BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString*)text
{
    if ([text isEqualToString:@"\n"]) {
        [textView resignFirstResponder];
        return NO;
    }
    return YES;
}

- (void)textViewDidChange:(UITextView *)textView{
    _placeHolderLabel.hidden = ![@"" isEqualToString:textView.text];
}

- (BOOL)textViewShouldBeginEditing:(UITextView *)textView{
    
    return YES;
}
@end
